import * as Types from 'containers/ActionTypes';

export default function (state = {}, action) {
  var publishedCount;
  switch (action.type) {
  case Types.MY.PUBLISHED.UPDATE_MY_PUBLISHED_COUNT:
    return Object.assign({}, state, {
      publishedCount: action.totalCount,
    });
  case Types.MY.PUBLISH_SUCCESS:
    publishedCount = state.publishedCount;
    return Object.assign({}, state, {
      publishedCount: publishedCount + 1,
    });
  case Types.MY.UNPUBLISH_SUCCESS:
    publishedCount = state.publishedCount;
    return Object.assign({}, state, {
      publishedCount: publishedCount - 1,
    });
  case Types.MY.DELETE_SUCCESS:
    publishedCount = state.publishedCount;
    return action.status === 'PUBLIC'
      ? Object.assign({}, state, { publishedCount: publishedCount - 1 })
      : state;
  default:
    return state;
  }
}
